package top.lyjwn.todo.weinxin.data.applet;

import com.alibaba.fastjson2.JSONException;
import com.alibaba.fastjson2.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 登录凭证校验。通过 wx.login 接口获得临时登录凭证 code 后传到开发者服务器调用此接口完成登录流程。更多使用方法详见 小程序登录。
 * 
 * @author luoyujie
 *
 */
public class Code2Session implements java.io.Serializable {

	private static final Logger log = LoggerFactory.getLogger("error");

	/**
	 * 
	 */
	private static final long serialVersionUID = -3036387955055683450L;
	/**
	 * 用户唯一标识
	 */
	private String openid;
	/**
	 * 会话密钥
	 */
	private String sessionKey;
	/**
	 * 用户在开放平台的唯一标识符，在满足 UnionID 下发条件的情况下会返回，详见 UnionID 机制说明。
	 */
	private String unionid;

	/**
	 * 错误返回码
	 */
	private String errcode;

	/**
	 * 说明
	 */
	private String errmsg;

	public Code2Session() {
	}

	public Code2Session(String openid, String sessionKey, String unionid, String errcode, String errmsg) {
		this.openid = openid;
		this.sessionKey = sessionKey;
		this.unionid = unionid;
		this.errcode = errcode;
		this.errmsg = errmsg;
	}

	public static Code2Session  builder(JSONObject jsonObject) {
		try {
			return jsonObject.toJavaObject(Code2Session.class);
		} catch (JSONException e) {
			log.error("WXBUser 转换失败", e);
		}
		return null;
	}

	public String getOpenid() {
		return openid;
	}

	public void setOpenid(String openid) {
		this.openid = openid;
	}

	public String getSessionKey() {
		return sessionKey;
	}

	public void setSessionKey(String sessionKey) {
		this.sessionKey = sessionKey;
	}

	public String getUnionid() {
		return unionid;
	}

	public void setUnionid(String unionid) {
		this.unionid = unionid;
	}


	public String getErrcode() {
		return errcode;
	}

	public void setErrcode(String errcode) {
		this.errcode = errcode;
	}

	public String getErrmsg() {
		return errmsg;
	}

	public void setErrmsg(String errmsg) {
		this.errmsg = errmsg;
	}
}
